/*defines.h*/
#define DATABUS PORTB
#define DATABUS_DIR TRISB

#define AdrBit1 RC0
#define AdrBit2 RA2
#define AdrBit3 RA3

#define AdrEnable 	RC5

// Pushbutton Interface 
#define selectButton() {RC0=1;RA2=0;RA3=0;}
// Button bitmasks
#define BUTTON_NEXT		0x01
#define BUTTON_RESET	0x10
#define BUTTON_SET		0x10
#define BUTTON_UP		0x20
#define BUTTON_DOWN		0x04
#define BUTTON_LEFT		0x02
#define BUTTON_RIGHT	0x08

#define MIN_SPEED_OVERFLOW	172 // ca 18s no signal equals 0,5 km/h min speed
#define SLEEP_COUNTER_MAX	160 // Go to sleep after ca. 20s no button and no signal

#define MM_PER_DIST_UNIT 			10000 //10/16m: 625
#define TIMER1_TICS_PER_TIMEUNIT	22500000 // for h/1600 1406250 
#define KPH_CORRECTION 				879 // (for 10m/h resolution) exact: 878,90625 

/* Power definitions */
#define GRAVITY_FACTOR	15	 // 9,81 /65 *100
#define AIR_RESISTANCE  1440   // 1/(C_d*A*rho)=3600^2/(1,2*0,75*10000)
#define ACCEL_FACTOR	678 // 678,1684  in (ticks/sec)
#define OVERALL_FACTOR	33 // mechanical loss:1.09, conversion 100/3600
#define ENERGY_FACTOR 	53711 // 0,22 human efficency, 2441 ticks/s, conv: 100/10000

/*Adresses on RC0 AN2 AN3 Chip enable RC5 */
#define  setAdress(x,y,z) {RC5=0;\ RC0=x ;\ RA2=y ;\ RA3=z ;\ RA4=1;}

//defines
#define INPUT 1		//port directions
#define OUTPUT 0
#define ALL_INPUT 0xFF		//port directions
#define ALL_OUTPUT 0x00
#define TRUE 1
#define FALSE 0
#define	HIGH 1
#define	LOW 0
#define	hi 1
#define	lo 0

#define	gie_on		GIE=1
#define gie_off		while(GIE==1) GIE=0

#define hibyte(x) ((unsigned char)(x>>8))
#define lobyte(x) ((unsigned char)(x&0xff))

#define byte0(x)		(unsigned char)(*(((unsigned char *)&x)+0))
#define byte1(x)		(unsigned char)(*(((unsigned char *)&x)+1))
#define byte2(x)		(unsigned char)(*(((unsigned char *)&x)+2))
#define byte3(x)		(unsigned char)(*(((unsigned char *)&x)+3))

/* Adresses in EEPROM */
#define time1HH 0x00
#define time1HL 0x01
#define time1LH 0x02
#define time1LL 0x03

#define time2HH 0x04
#define time2HL 0x05
#define time2LH 0x06
#define time2LL 0x07

#define distance1HH 0x08
#define distance1HL 0x09
#define distance1LH 0x0a
#define distance1LL 0x0b

#define distance2HH 0x0c
#define distance2HL 0x0d
#define distance2LH 0x0e
#define distance2LL 0x0f

#define avgSpeed1H	0x10
#define avgSpeed1L	0x11

#define avgSpeed2H	0x12
#define avgSpeed2L	0x13

#define tickCounter1HH	0x13
#define tickCounter1HL	0x14
#define tickCounter1LH	0x15
#define tickCounter1LL	0x16

#define tickCounter2HH	0x17
#define tickCounter2HL	0x18
#define tickCounter2LH	0x19
#define tickCounter2LL	0x1a

#define wheelCircumferenceH	0x1b
#define wheelCircumferenceL	0x1c

#define weightL	0x1d

#define energyHH	0x1e
#define energyHL	0x1F
#define energyLH	0x20
#define energyLL	0x21
